import React from 'react'
import { HashRouter, Route, Redirect, Switch } from 'react-router-dom'
import Index from './container/Index'
import Login from './pages/login/login'
// 私有路由的判断
const PrivateRoute = ({component:Com,...rest})=>{
    return <Route {...rest} render={({location})=>{
        const userinfo = localStorage.getItem('isLogin');
        if(userinfo){
            return <Com/>
        }else{
            return <Redirect to={{
                pathname:'/login',
                state:location.pathname 
            }}/>
        }
    }}/>
}




const IndexRouter=()=> {
    return (
        <HashRouter>
            <div>
                <Switch>
                    
                    <Route path="/login" component={Login} />
                    {/* 判断登录 重定向 */}
                    <PrivateRoute path='/' component={Index}/>
                </Switch>
            </div>
        </HashRouter>
        
    )
}
export default IndexRouter